package com.spa.application.dto;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * 分页返回的结果.
 *
 * @author liangjun
 */
@Data
public class PageResult<T> {

    private Long total = 0l;

    private Long current = 1l;

    private Long size = 10l;

    private List<T> records = new ArrayList<>();

    public static <T> PageResult<T> pageToDto(Page<?> ipage, Class<T> t){
        List<T> dtoList = BeanUtil.copyToList(ipage.getRecords(), t);
        PageResult<T> pageResult = new PageResult<>();
        pageResult.setCurrent(ipage.getCurrent());
        pageResult.setSize(ipage.getSize());
        pageResult.setTotal(ipage.getTotal());
        pageResult.setRecords(dtoList);
        return pageResult;
    }

}
